<template>
  <div class="wrap-recommended">
    <div class="header">
      <slot name="header">
        <span>Recommended Products</span>
      </slot>
    </div>
    <div class="content">
      <div class="item" v-for="item in recommendList">
        <el-image class="item-img" :src="item.imageUrl" />
        <div class="item-info">
          <el-text class="text" :line-clamp="2"
            >{{ item.subjectTrans }}
          </el-text>
          <div class="graycolor">
            Lists: {{ Math.floor(Math.random() * (2000 - 0 + 1)) + 0 }}
          </div>
          <div class="money">
            {{ item.unit ? item.unit : '$' }}{{ item.price }}
          </div>
        </div>
        <div class="btn-group">
          <el-button
            color="#FA4756"
            class="recommend-btn"
            style="background-color: #fff; color: #fa4756"
            plain
            >Connect
          </el-button>
          <el-button
            class="recommend-btn"
            color="#FA4756"
            @click="onGo2Detail(item)"
            >List
          </el-button>
        </div>
      </div>

      <div class="line-item" v-if="showAddLoading" v-for="item in addCount">
        <el-skeleton animated>
          <template #template>
            <el-skeleton-item class="item-img" variant="image" />
            <div class="item-info">
              <el-skeleton-item class="info-line" variant="p" />
              <el-skeleton-item class="info-line" variant="p" />
            </div>
            <div class="btn-group">
              <el-skeleton-item class="btn-line-lf" variant="p" />
              <el-skeleton-item class="btn-line-rt" variant="p" />
            </div>
          </template>
        </el-skeleton>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { onMounted } from 'vue'

const props = defineProps({
  skeletonLoading: {
    type: Boolean,
    default: false
  },
  showAddLoading: {
    type: Boolean,
    default: false
  },
  addCount: {
    type: Number,
    default: 1
  },
  recommendList: {
    type: Array,
    default: () => []
  }
})

onMounted(() => {})

// const router = useRouter()
const onGo2Detail = (item: any) => {
  window.open(`/productDetail?id=${item.offerId}`, '_blank')
  // router.push({ name: 'ProductDetail', query: { id: item.offerId } })
}
</script>
<style lang="scss" scoped>
.wrap-recommended {
  display: flex;
  flex-direction: column;
  padding-bottom: 20px;
  background-color: #fff;

  .header {
    height: 72px;
    border-bottom: 1px solid #e9e9ec;
    padding: 0 28px;
    display: flex;
    font-size: 24px;
    align-items: center;
  }

  .content {
    display: grid;
    padding: 24px 10px 24px 28px;
    grid-template-columns: repeat(6, 15%);
    grid-column-gap: 20px;
    grid-row-gap: 24px;

    .item,
    .line-item {
      height: 290px;
      display: flex;
      flex-direction: column;
      box-sizing: border-box;
      padding: 4px;
      border: 1px solid transparent;

      .item-img {
        width: 100%;
        height: 174px;
      }

      .item-info {
        flex: 1;
        padding: 6px 0 8px 0;

        .text {
          color: #333333;
          font-size: 12px;
          line-height: 16px;
        }

        .money {
          padding-top: 3px;
          font-size: 16px;
        }
      }

      .btn-group {
        display: flex;
        justify-content: space-between;

        .recommend-btn {
          width: 80px;
          height: 24px;
          font-size: 12px;
          border-radius: 2px;
        }
      }
    }

    .item:hover {
      border: 1px solid red;
    }
  }

  // 骨架屏
  .header-box {
    height: 40px;
    display: flex;
    justify-content: space-between;

    .line-lf {
      width: 300px;
      height: 100%;
    }

    .line-rt {
      width: 160px;
      height: 100%;
    }
  }

  .content {
    .line-info {
      margin: 10px 0;
      height: 20px;
    }

    .btn-line-lf {
      width: 45%;
    }

    .btn-line-rt {
      width: 45%;
    }
  }
}
</style>
